package com.qfedu.controller;

import com.github.pagehelper.Page;
import com.qfedu.entity.User;
import com.qfedu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户查询控制台
 */
@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("userList.do")
    @ResponseBody
    public Map<String, Object> findAllUser(Integer page, Integer limit) {
        List<User> user = userService.findAllUser(page, limit);
        //获取数据总数
        long total = ((Page) user).getTotal();
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", total);
        map.put("data", user);

        return map;
    }
}
